﻿Imports System.ComponentModel
Namespace UI
	Class DesignWindow
		Implements INotifyPropertyChanged
		Public Event PropertyChanged(sender As Object, e As PropertyChangedEventArgs) Implements INotifyPropertyChanged.PropertyChanged
		Private Sub RaisePropertyChanged(PropertyName As String)
			RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(PropertyName))
		End Sub

		''' <summary>
		''' When the window closes check to make sure the user really wants to exit the application.
		''' </summary>
		''' <param name="sender"></param>
		''' <param name="e"></param>
		''' <remarks></remarks>
		Private Async Sub DesignWindow_Closing(sender As Object, e As ComponentModel.CancelEventArgs)	' Handles Me.Closing

			If MsgBox("Are you sure you want to exit this application? Any currently playing cues will be terminated.", MsgBoxStyle.YesNo, "Are you sure you want to exit?") = MsgBoxResult.No Then
				e.Cancel = True
			Else
				If My.Application.Show.ShowFile.IsSaved = False AndAlso My.Application.Show.ShowFile.CueList.Count > 0 Then
					Dim result As MsgBoxResult = MsgBox("The current show has changes that haven't been saved. Do you want to save these changes before exiting?", MsgBoxStyle.YesNoCancel)
					If result = MsgBoxResult.Yes Then
						My.Application.Show.ShowFile.Save()
					ElseIf result = MsgBoxResult.Cancel Then
						e.Cancel = True
						Return
					End If
				End If
				'StopCues_Click(Me, New RoutedEventArgs)
				'Await My.Application.Show.StopAllCues()
				Await My.Application.Show.ShowFile.CueList.StopAllCues()
				RemoveHandler Me.LocationChanged, AddressOf DesignWindow_LocationChanged
				RemoveHandler Me.SizeChanged, AddressOf DesignWindow_SizeChanged
				RemoveHandler Me.StateChanged, AddressOf DesignWindow_StateChanged
				My.Application.Shutdown()
			End If
		End Sub

		''' <summary>
		''' When the window loads create references to the recent projects.
		''' </summary>
		''' <param name="sender"></param>
		''' <param name="e"></param>
		''' <remarks></remarks>
		Private Sub DesignWindow_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
			Me.Left = My.Settings.DesignWindowPosition.X
			Me.Top = My.Settings.DesignWindowPosition.Y
			Me.Width = My.Settings.DesignWindowSize.Width
			Me.Height = My.Settings.DesignWindowSize.Height
			Me.WindowState = My.Settings.DesignWindowState
			AddHandler Me.LocationChanged, AddressOf DesignWindow_LocationChanged
			AddHandler Me.SizeChanged, AddressOf DesignWindow_SizeChanged
			AddHandler Me.StateChanged, AddressOf DesignWindow_StateChanged
			Me.DataContext = Application.Current.Resources("ShowFile")
			SetupRecentProjects()
			AddHandler Me.Closing, AddressOf DesignWindow_Closing
			'CommandManager.AddCanExecuteHandler(AddAudio, AddressOf Cues.CanExecuteEditing)
			'CommandManager.AddExecutedHandler(AddAudio, AddressOf Cues.ExecuteAddAudioCue)

			'My.Application.Show.ShowFile.CueList.AddCue(New Cues.Audio)
			Cues.Cues.Focus()
			'Cues.Cues.SelectedIndex = 0
			'CType(Cues.Cues.SelectedItem, ListViewItem).ContextMenu.IsOpen = True
			'My.Application.Show.ShowFile.CueList.RemoveAt(0)
		End Sub

		''' <summary>
		''' Sets up the recent projects list.
		''' </summary>
		''' <remarks></remarks>
		Private Sub SetupRecentProjects()
			Try
				RecentProjects.Items.Clear()
				Dim l As List(Of String) = My.Settings.RecentProjects.Items
				For i = 0 To 3
					Dim m As New MenuItem()
					If l.Item(i).Length > 35 Then
						m.Header = l.Item(i).Substring(l.Item(i).Length - 35)
					Else
						m.Header = l.Item(i)
					End If
					m.Command = Commands.OpenRecentProject
					m.CommandParameter = l.Item(i)
					RecentProjects.Items.Add(m)
				Next
			Catch
			End Try
		End Sub



#Region "Events"
		Public Event MasterVolumeChanged(sender As Object, e As EventArgs)
#End Region

#Region "Properties"

		''' <summary>
		''' Indicates whether the application is currently in fullscreen mode.
		''' </summary>
		''' <value></value>
		''' <returns></returns>
		''' <remarks></remarks>
		Public Property IsFullScreen As Boolean
			Get
				Return IsFullScreenProperty
			End Get
			Set(value As Boolean)
				If IsFullScreenProperty <> value Then
					IsFullScreenProperty = value
					RaisePropertyChanged("IsFullScreen")
				End If
			End Set
		End Property
		Private IsFullScreenProperty As Boolean = False

		''' <summary>
		''' Returns true when the program is in show mode.
		''' </summary>
		''' <value></value>
		''' <returns></returns>
		''' <remarks></remarks>
		Public Property IsInShowMode As Boolean
			Get
				Return IsInShowModeProperty
			End Get
			Set(value As Boolean)
				If IsInShowModeProperty <> value Then
					IsInShowModeProperty = value
					RaisePropertyChanged("IsInShowMode")
					RaisePropertyChanged("IsNotInShowMode")
				End If
			End Set
		End Property
		Private IsInShowModeProperty As Boolean = False

		''' <summary>
		''' Returns True when the program is not in show mode.
		''' </summary>
		''' <value></value>
		''' <returns></returns>
		''' <remarks></remarks>
		Public Property IsNotInShowMode As Boolean
			Get
				If IsInShowMode Then
					Return False
				Else
					Return True
				End If
			End Get
			Set(value As Boolean)
				If IsNotInShowMode <> value Then
					If value = True Then
						IsInShowMode = False
					Else
						IsInShowMode = True
					End If
				End If
			End Set
		End Property

		''' <summary>
		''' Gets and sets whether the server is running, prompting the starting and stopping of the remote server.
		''' </summary>
		''' <value></value>
		''' <returns></returns>
		''' <remarks></remarks>
		Public Property IsServerRunning As Boolean
			Get
				Return IsServerRunningProperty
			End Get
			Set(value As Boolean)
				If IsServerRunning Then
					RemoteServer.StopServr()
					IsServerRunningProperty = False
				Else
					RemoteServer.StartServr()
					IsServerRunningProperty = True
				End If
				RaisePropertyChanged("IsServerRunning")
			End Set
		End Property
		''' <summary>
		''' Represents the IsServerRunning property.
		''' </summary>
		''' <remarks></remarks>
		Private IsServerRunningProperty As Boolean = False

		''' <summary>
		''' The RemoteServer class
		''' </summary>
		''' <remarks></remarks>
		Private WithEvents RemoteServer As New Server.RemoteServer()


		''' <summary>
		''' Indicates whether the show window is currently in the Mixer View mode.
		''' </summary>
		''' <remarks></remarks>
		Private IsMixerProperty As Boolean = False
		Public Property IsMixer As Boolean
			Get
				Return IsMixerProperty
			End Get
			Set(value As Boolean)
				If IsMixerProperty <> value Then
					IsMixerProperty = value
					RaisePropertyChanged("IsMixer")
					If IsMixerProperty Then
						Dim bb As New Binding("ShowFile.ActiveCues")
						bb.Mode = BindingMode.OneWay
						MixerFaderView.SetBinding(ListView.ItemsSourceProperty, bb)
					Else
						Dim bb As New Binding("ShowFile.CueList")
						bb.Mode = BindingMode.OneWay
						Cues.SetBinding(Q2Q.Controls.CueList.CueListingProperty, bb)
						MixerFaderView.ItemsSource = Nothing
					End If
				End If
			End Set
		End Property




#Region "Application Setting Accessors"

		''' <summary>
		''' Gets/Sets the master volume level from the application settings.
		''' </summary>
		''' <value></value>
		''' <returns></returns>
		''' <remarks></remarks>
		Public Property MasterVolume As Single
			Get
				Return My.Settings.MasterVolume
			End Get
			Set(value As Single)
				Try
					If My.Settings.MasterVolume <> value Then
						My.Settings.MasterVolume = value
						RaisePropertyChanged("MasterVolume")
						RaiseEvent MasterVolumeChanged(Me, New EventArgs())
					End If
				Catch ex As Exception
				End Try
			End Set
		End Property

		''' <summary>
		''' Used to access the application setting "EnableRemoteServer"
		''' </summary>
		''' <value></value>
		''' <returns></returns>
		''' <remarks></remarks>
		Public Property RemoteEnabled As Boolean
			Get
				Return My.Settings.EnableRemoteServer
			End Get
			Set(value As Boolean)
				Try
					My.Settings.EnableRemoteServer = value
					My.Settings.Save()
					RaisePropertyChanged("RemoteEnabled")
				Catch ex As Exception
				End Try
			End Set
		End Property

		''' <summary>
		''' Used to access the application setting "DefaultCueFontSize"
		''' </summary>
		''' <value></value>
		''' <returns></returns>
		''' <remarks></remarks>
		Public Property DefaultCueFontSize As Double
			Get
				Return My.Settings.DefaultCueFontSize
			End Get
			Set(value As Double)
				Try
					My.Settings.DefaultCueFontSize = value
					My.Settings.Save()
					RaisePropertyChanged("DefaultCueFontSize")
				Catch ex As Exception

				End Try
			End Set
		End Property

		''' <summary>
		''' Used to access the application setting "ShowConsole"
		''' </summary>
		''' <value></value>
		''' <returns></returns>
		''' <remarks></remarks>
		Public Property ShowConsole As Boolean
			Get
				Return My.Settings.ShowConsole
			End Get
			Set(value As Boolean)
				Try
					My.Settings.ShowConsole = value
					My.Settings.Save()
					RaisePropertyChanged("ShowConsole")
					If value Then
						TheGrid.RowDefinitions.Item(2).Height = New GridLength(60, GridUnitType.Pixel)
					Else
						TheGrid.RowDefinitions.Item(2).Height = New GridLength(0, GridUnitType.Pixel)
					End If
				Catch ex As Exception

				End Try
			End Set
		End Property

		''' <summary>
		''' Indicates whether the GO button and MasterVolume levels should be visible.
		''' </summary>
		''' <value></value>
		''' <returns></returns>
		''' <remarks></remarks>
		Public Property ShowGoAndVolume As Boolean
			Get
				Return My.Settings.ShowGoAndVolume
			End Get
			Set(value As Boolean)
				Try
					My.Settings.ShowGoAndVolume = value
					My.Settings.Save()
					RaisePropertyChanged("ShowGoAndVolume")
				Catch ex As Exception
				End Try
			End Set
		End Property
#End Region

#End Region

#Region "Commands"

#Region "Common Conditionals"

		Public Sub CanExecute_Save(sender As Object, e As CanExecuteRoutedEventArgs)
			If IsInShowMode OrElse My.Application.Show.ShowFile.CueList.IsActive Then
				e.CanExecute = False
				e.Handled = True
				Return
			End If
			If My.Application.Show.ShowFile.CueList.Count > 0 Then
				e.CanExecute = True
			Else
				e.CanExecute = False
			End If
			e.Handled = True
		End Sub

		Public Sub CanExecute_HasActiveCues(sender As Object, e As CanExecuteRoutedEventArgs)
            If My.Application.Show.ShowFile.CueList.IsActive Then
                e.CanExecute = True
            Else
                e.CanExecute = False
                e.Handled = True
            End If
        End Sub

		''' <summary>
		''' Used to check validity of commands based on at least one cue existing in the cue list.
		''' </summary>
		''' <param name="sender"></param>
		''' <param name="e"></param>
		''' <remarks></remarks>
		Public Sub CanExecute_HasMinOneCue(sender As Object, e As CanExecuteRoutedEventArgs)
			If IsInShowMode Then
				e.CanExecute = False
				Return
			End If
			If My.Application.Show.ShowFile.CueList.Count > 0 Then
				e.CanExecute = True
			Else
				e.CanExecute = False
			End If
		End Sub

		''' <summary>
		''' Used to check validity of commands based on at least one cue selected in the list, not in show mode.
		''' </summary>
		''' <param name="sender"></param>
		''' <param name="e"></param>
		''' <remarks></remarks>
		Public Sub CanExecute_HasMinOneCueSelected(sender As Object, e As CanExecuteRoutedEventArgs)
			If IsInShowMode Then
				e.CanExecute = False
				Return
			End If
			If Cues.SelectedItems.Count > 0 Then
				e.CanExecute = True
			Else
				e.CanExecute = False
			End If
		End Sub

		''' <summary>
		''' If the show is in show mode the command cannot be used.
		''' </summary>
		''' <param name="sender"></param>
		''' <param name="e"></param>
		''' <remarks></remarks>
		Public Sub CanExecute_NotInShowMode(sender As Object, e As CanExecuteRoutedEventArgs)
			If IsInShowMode Then
				e.CanExecute = False
			Else
				e.CanExecute = True
			End If
		End Sub

        Public Sub CanExecute_IsInShowMode(sender As Object, e As CanExecuteRoutedEventArgs)
            If IsInShowMode Then
                e.CanExecute = True
            Else
                e.CanExecute = False
            End If
        End Sub

        Public Sub CanExecute_Copy(sender As Object, e As CanExecuteRoutedEventArgs)
            If My.Application.Show.ShowFile.CueList.GetSelectedCueCount = 1 Then
                e.CanExecute = True
            Else
                e.CanExecute = False
            End If
            e.Handled = True
        End Sub

        Public Sub CanExecute_Paste(sender As Object, e As CanExecuteRoutedEventArgs)
            If My.Application.Show.ShowFile.CueList.GetSelectedCueCount > 0 Then
                e.CanExecute = True
            Else
                e.CanExecute = False
            End If
            e.Handled = True
        End Sub




#End Region
#Region "Command Bindings"

        ''' <summary>
        ''' Copies the first selected cue into memory.
        ''' </summary>
        ''' <param name="sender"></param>
        ''' <param name="e"></param>
        Public Sub ExecuteCopy(sender As Object, e As ExecutedRoutedEventArgs)
            Dim cue As Cues.CueBase = My.Application.Show.ShowFile.CueList.GetSelectedCue()
            If cue IsNot Nothing Then
                My.Computer.Clipboard.SetData("Q2CueCopyCueData", cue)
            End If
            e.Handled = True
        End Sub

        Public Sub ExecutePaste(sender As Object, e As ExecutedRoutedEventArgs)
            If My.Computer.Clipboard.ContainsData("Q2CueCopyCueData") Then
                Q2Q.Cues.Helpers.Paste.PasteCueData(CType(My.Computer.Clipboard.GetData("Q2CueCopyCueData"), Cues.CueBase), My.Application.Show.ShowFile.CueList.GetSelectedCues)
            End If
        End Sub

        ''' <summary>
        ''' Creates an archive of the project, copying all the audio files to the archive folder. This doesn't zip the archive.
        ''' </summary>
        ''' <param name="sender"></param>
        ''' <param name="e"></param>
        ''' <remarks></remarks>
        Public Sub ExecuteCreateArchive(sender As Object, e As ExecutedRoutedEventArgs)
			Try
				'My.Application.Show.ShowFile.Consolidate()
				Dim ArcWin As New UI.Windows.Archive()
				ArcWin.Owner = Me
				ArcWin.ShowDialog()
			Catch ex As Exception
				My.Application.Show.Console.SendMessage("Error Encountered. Use VerboseDebugging to view more detail.", ex)
			End Try
			e.Handled = True
		End Sub

		''' <summary>
		''' When executed puts the window into fullscreen mode.
		''' </summary>
		''' <param name="sender"></param>
		''' <param name="e"></param>
		''' <remarks></remarks>
		Public Sub ExecuteFullScreen(sender As Object, e As ExecutedRoutedEventArgs)
			If Not IsFullScreen Then
				'Me.WindowState = Windows.WindowState.Normal
				'Me.WindowState = Windows.WindowState.Maximized
				'Me.Topmost = True
				IsFullScreen = True
				Me.WindowState = System.Windows.WindowState.Normal
				Me.WindowStyle = System.Windows.WindowStyle.None
				Me.WindowState = System.Windows.WindowState.Maximized
			Else
				Me.WindowStyle = System.Windows.WindowStyle.SingleBorderWindow
				'Me.Topmost = False
				Me.WindowState = System.Windows.WindowState.Maximized
				IsFullScreen = False
			End If
			e.Handled = True
		End Sub

		''' <summary>
		''' Opens the settings dialog.
		''' </summary>
		''' <param name="sender"></param>
		''' <param name="e"></param>
		''' <remarks></remarks>
		Public Sub ExecuteSettings(sender As Object, e As ExecutedRoutedEventArgs)
			Try
				Dim sett As New ApplicationSettings
				sett.Owner = Me
				sett.ShowDialog()
				If sett.DialogResult = True Then
					RaisePropertyChanged("RemoteEnabled")
					RaisePropertyChanged("DefaultCueFontSize")
				End If
			Catch ex As Exception
			End Try
			e.Handled = True
		End Sub

		''' <summary>
		''' Opens the program's help file.
		''' </summary>
		''' <param name="sender"></param>
		''' <param name="e"></param>
		''' <remarks></remarks>
		Public Sub ExecuteHelp(sender As Object, e As ExecutedRoutedEventArgs)
			Try
				System.Windows.Forms.Help.ShowHelp(Nothing, My.Application.Info.DirectoryPath & "\Q2Cue Help.chm")
			Catch ex As Exception
			End Try
			e.Handled = True
		End Sub

		''' <summary>
		''' Opens the About popup.
		''' </summary>
		''' <param name="sender"></param>
		''' <param name="e"></param>
		''' <remarks></remarks>
		Public Sub ExecuteAbout(sender As Object, e As ExecutedRoutedEventArgs)
			Try
				Dim abt As New About
				abt.Show()
			Catch
			End Try
			e.Handled = True
		End Sub

		Public Async Sub ExecuteStopAllCues(sender As Object, e As ExecutedRoutedEventArgs)
			Await My.Application.Show.ShowFile.CueList.StopAllCues()
			e.Handled = True
		End Sub

		Public Async Sub ExecuteResetShow(sender As Object, e As ExecutedRoutedEventArgs)
			Await My.Application.Show.ShowFile.CueList.Reset()
		End Sub

		Public Sub ExecuteGo(sender As Object, e As ExecutedRoutedEventArgs)
			If IsNotInShowMode AndAlso e.OriginalSource.GetType Is GetType(DesignWindow) Then
				e.Handled = True
				Return
			End If
			My.Application.Show.ShowFile.CueList.Go()
			If Cues.Visibility = System.Windows.Visibility.Visible Then
				Try
					Cues.ScrollIntoView(My.Application.Show.ShowFile.LastActiveCue())
				Catch
				End Try
			End If
			e.Handled = True
		End Sub

		Public Async Sub ExecuteOpenRecentProject(sender As Object, e As ExecutedRoutedEventArgs)
			Dim s As Shows.ShowFile = Await Shows.ShowFile.Load(e.Parameter)
			If s IsNot Nothing Then
				My.Application.Show.ShowFile = s
			Else
				Return
			End If
			My.Application.Show.Console.SendMessage("Recent Show File Opened")
			SetupRecentProjects()
			e.Handled = True
		End Sub


#End Region


		''' <summary>
		''' Clears the current show file and creates a new blank file.
		''' </summary>
		''' <param name="sender"></param>
		''' <param name="e"></param>
		''' <remarks></remarks>
		Private Async Sub OnExecuteNewProject(ByVal sender As Object, ByVal e As ExecutedRoutedEventArgs)
			' Perform the actions associated with the command.
			If My.Application.Show.ShowFile.IsSaved = False AndAlso My.Application.Show.ShowFile.CueList.Count > 0 Then
				Dim result As MsgBoxResult = MsgBox("The current show has had changes made since it was last saved. Do you wish to save it before creating a new show?", MsgBoxStyle.YesNoCancel, "Save Current Show?")
				If result = MsgBoxResult.Yes Then
					My.Application.Show.ShowFile.Save()
				ElseIf result = MsgBoxResult.Cancel Then
					Return
				End If
			End If
			Await My.Application.Show.ShowFile.CueList.StopAllCues()
			For Each cue In My.Application.Show.ShowFile.CueList
				RemoveHandler cue.PropertyChanged, AddressOf My.Application.Show.ShowFile.ACueIsChanged
			Next
			My.Application.Show.ShowFile = New Shows.ShowFile
			My.Application.Show.Console.SendMessage("Command: New Show File Executed")
			' Work was done for this command. Mark the event as handled.
			e.Handled = True
		End Sub



		''' <summary>
		''' Runs the show file's open project subroutine.
		''' </summary>
		''' <param name="sender"></param>
		''' <param name="e"></param>
		''' <remarks></remarks>
		Private Async Sub OnExecuteOpenProject(ByVal sender As Object, ByVal e As ExecutedRoutedEventArgs)
			Dim s As Shows.ShowFile = Await Shows.ShowFile.Load()
			If s IsNot Nothing Then
				My.Application.Show.ShowFile = s
			End If
			My.Application.Show.Console.SendMessage("Command: Open Show File Executed")
			SetupRecentProjects()
			' Work was done for this command. Mark the event as handled.
			e.Handled = True
		End Sub


#Region "Save Show File"
		''' <summary>
		''' Runs the show file's save subroutine.
		''' </summary>
		''' <param name="sender"></param>
		''' <param name="e"></param>
		''' <remarks></remarks>
		Private Sub OnExecuteSaveProject(ByVal sender As Object, ByVal e As ExecutedRoutedEventArgs)
			' Perform the actions associated with the command.
			If My.Application.Show.ShowFile.IsArchive Then
				My.Application.Show.ShowFile.Consolidate()
			Else
				My.Application.Show.ShowFile.Save()
			End If
			My.Application.Show.Console.SendMessage("Command: Save Show File Executed")
			SetupRecentProjects()
			' Work was done for this command. Mark the event as handled.
			e.Handled = True
		End Sub
		''' <summary>
		''' Runs the show file's save-as subroutine.
		''' </summary>
		''' <param name="sender"></param>
		''' <param name="e"></param>
		''' <remarks></remarks>
		Private Sub OnExecuteSaveAsProject(ByVal sender As Object, ByVal e As ExecutedRoutedEventArgs)
			' Perform the actions associated with the command.
			My.Application.Show.ShowFile.SaveAs()
			My.Application.Show.Console.SendMessage("Command: Save As Executed")
			SetupRecentProjects()
			' Work was done for this command. Mark the event as handled.
			e.Handled = True
		End Sub
#End Region
#Region "Exit Application"
		''' <summary>
		''' When this command is run we close the window.
		''' </summary>
		''' <param name="sender"></param>
		''' <param name="e"></param>
		''' <remarks></remarks>
		Private Sub OnExecuteExitApplication(ByVal sender As Object, ByVal e As ExecutedRoutedEventArgs)
			' Perform the actions associated with the command.
			Me.Close()

			' Work was done for this command. Mark the event as handled.
			e.Handled = True
		End Sub

#End Region

#End Region
#Region "Server Actions"

		''' <summary>
		''' Runs commands received from a remote device through the Remote Server.
		''' </summary>
		''' <param name="command"></param>
		''' <param name="optionValue"></param>
		''' <remarks></remarks>
		Private Async Sub RemoteServer_SendCommand(command As String, optionValue As String) Handles RemoteServer.SendCommand
			Try
				'Await Me.Dispatcher.Invoke(Function()

				Select Case command
					Case "Go"
						My.Application.Show.ShowFile.CueList.Go()
						If Cues.Visibility = System.Windows.Visibility.Visible Then
							Try
								Cues.ScrollIntoView(My.Application.Show.ShowFile.LastActiveCue())
							Catch
							End Try
						End If
					Case "BumpCueStatus"
						CType(My.Application.Show.ShowFile.CueList.Where(Function(c) CType(c, Cues.CueBase).Number = CInt(optionValue))(0), Cues.CueBase).BumpStatus()
					Case "StopAllCues"
						Await My.Application.Show.ShowFile.CueList.StopAllCues()
					Case "ClearCues"
						For Each c As Cues.CueBase In My.Application.Show.ShowFile.CueList.Where(Function(cue) cue.Status = Q2Q.Cues.CueStatus.Cued)
							c.Status = Q2Q.Cues.CueStatus.Standby
						Next
				End Select
			Catch ex As Exception
				My.Application.Show.Console.SendMessage("There was a problem executing a command from a remote device location.", ex)
			End Try
		End Sub

#End Region


		''' <summary>
		''' Saves the window size when the window is resized.
		''' </summary>
		''' <param name="sender"></param>
		''' <param name="e"></param>
		''' <remarks></remarks>
		Private Sub DesignWindow_SizeChanged(sender As Object, e As SizeChangedEventArgs)
			Try
				If WindowState = System.Windows.WindowState.Normal Then
					My.Settings.DesignWindowSize = e.NewSize
					My.Settings.Save()
				End If
			Catch
			End Try
		End Sub

		''' <summary>
		''' Saves the window's position when it is moved.
		''' </summary>
		''' <param name="sender"></param>
		''' <param name="e"></param>
		''' <remarks></remarks>
		Private Sub DesignWindow_LocationChanged(sender As Object, e As EventArgs)
			Try
				If WindowState = System.Windows.WindowState.Normal Then
					If Me.Left < 0 AndAlso Me.Top < 0 Then
						Return
					End If
					Dim xy As New System.Windows.Point(Me.Left, Me.Top)
					My.Settings.DesignWindowPosition = xy
					My.Settings.Save()
				End If
			Catch
			End Try
		End Sub

		''' <summary>
		''' Saves the window's state when it is maximized or normalized. Minimized changes are ignored.
		''' </summary>
		''' <param name="sender"></param>
		''' <param name="e"></param>
		''' <remarks></remarks>
		Private Sub DesignWindow_StateChanged(sender As Object, e As EventArgs)
			Try

				If Me.WindowState = System.Windows.WindowState.Maximized OrElse Me.WindowState = System.Windows.WindowState.Normal Then
					My.Settings.DesignWindowState = Me.WindowState
					My.Settings.Save()
				End If
			Catch
			End Try
		End Sub



		''' <summary>
		''' Updates local settings used to access application settings.
		''' </summary>
		''' <remarks></remarks>
		Public Sub UpdateSettingProperties()
			RaisePropertyChanged("ShowConsole")
		End Sub

		''' <summary>
		''' Forcues focus on the cuelist listview to ensure Commands work. /Hack
		''' </summary>
		''' <param name="sender"></param>
		''' <param name="e"></param>
		''' <remarks></remarks>
		Private Sub Menu_MouseEnter(sender As Object, e As MouseEventArgs) Handles Menu.MouseEnter
            'Cues.Cues.Focus()
        End Sub

	End Class
End Namespace